package com.hongying.config;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class UserAop {

    Logger log = LoggerFactory.getLogger(UserAop.class);

    @Pointcut("@annotation(com.hongying.annotations.Log)")
    public void logPointCut(){}



    @Before("logPointCut()")
    public void doBefore(JoinPoint point){


        log.info("before log do ...... ");


        Signature signature = point.getSignature();

        String typeName = signature.getDeclaringTypeName();

        String methodName = signature.getName();
    }

    @After(value = "logPointCut()")
    public void doAfter(JoinPoint point){
        log.info("after log do .... ");
        Signature signature = point.getSignature();

        String typeName = signature.getDeclaringTypeName();

        String methodName = signature.getName();



    }

    @AfterThrowing(value = "logPointCut()",throwing = "exception")
    public void doAfterException(Exception exception){
        log.info("exception  log do ....{}",exception.getMessage());

    }

    @AfterReturning(value = "logPointCut()",returning = "result")
    public void doAfterReturn(Object result){

        log.info("after returning do ...{}",result);
    }

    @Around(value = "logPointCut()")
    public void doAround(ProceedingJoinPoint point){
        log.info("around log do ..... ");
        Signature signature = point.getSignature();

        String typeName = signature.getDeclaringTypeName();

        log.info("typeName: {}",typeName);

        try {
            Object proceed = point.proceed();

        } catch (Throwable e) {
            throw new RuntimeException(e);
        }

        String methodName = signature.getName();
        log.info("methodName: {}",methodName);
    }










}
